# 自定义一个异常，继承了Exception类
class ValueTooSmallError(Exception):
    """Raised when the input value is too small"""
    pass


# 自定义一个异常，继承了Exception类
class ValueTooLargeError(Exception):
    """Raised when the input value is too large"""
    pass


# our main program
# user guesses a number until he/she gets it right
# you need to guess this number
number = 10

while True:
    try:
        i_num = int(input("Enter a number: "))
        if i_num < number:
            # raise 抛出异常
            raise ValueTooSmallError
        elif i_num > number:
            # raise 抛出异常
            raise ValueTooLargeError
        else:
            print("Congratulations! You guessed it correctly.")
            break
    except ValueTooSmallError:
        print("This value is too small, try again!")
    except ValueTooLargeError:
        print("This value is too large, try again!")
